#encoding:utf8 

from platform import platform
import subcmd
import logging
import argparse

class Dlog:
    @classmethod
    def logger(cls):
        logging.basicConfig(level=logging.INFO)
        return logging.getLogger("d")

class Env:

    is_debug = False

    cocos_bin = ""
    proj_path = ""
    platform = ""

    hotpub_dir = ""
    hotpub_remote_url = ""

    def __init__(self, **kwads):
        self.cocos_bin = kwads.get("cocos_bin")
        self.proj_path =  kwads.get("proj_path")
        self.platform = kwads.get ("platform", "android") 

    def set_hotpack(self, **kwads):
        self.hotpub_remote_url = kwads.get("hotpack_url")
        self.hotpub_dir = kwads.get("hotpack_dir", "remote-assests")
        
        
    def __str__(self):
        cont = '''
=====ENV=====
cocos_bin = {bin}
proj_path = {path}
platform = {platform}
hotpub_dir = {hotpub_dir}
hotpub_remote_url = {hotpub_remote_url}
=====ENV=====
        '''.format(bin = self.cocos_bin, path = self.proj_path,platform = self.platform, hotpub_dir = self.hotpub_dir, hotpub_remote_url = self.hotpub_remote_url)
        return cont

class _Ccmd:
    
    def __init__(self, env):
        self._env = env

    def lazy_hot_release(self, **kwads):
        #cocos pack 
        p = subcmd.cocos_pack.CocosPack(self._env)
        build_p = p.pack()
        #cocos upload
        u = subcmd.cocos_upload_static.CocosUpload(self._env)
        is_upload = kwads.get("is_upload", False)
        if is_upload:
            u.upload_to_sftp()
            return 
        copy_p = kwads.get("copy_p")
        if (copy_p):
            u.copy_pack(build_p, copy_p)

        


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="hava fun:3")
    parser.add_argument('--platform',type=str,help='资源平台')
    parser.add_argument('--proj_path', type=str, help="工程路径")
    args = parser.parse_args()
    env = Env(
        cocos_bin = "/Applications/CocosCreator/Creator/2.4.3/CocosCreator.app/Contents/MacOS/CocosCreator",
        proj_path = args.proj_path,
        platform =  args.platform
    )
    env.set_hotpack(
        hotpack_url = "http://static.bbclient.icu:8081/shizi_dev/update/", 
        hotpack_dir = "remote-assets"
    )
    print(env)
    cmd = _Ccmd(env)
    cmd.lazy_hot_release(
        copy_p = "/Users/dwb/Desktop/ccmd-server/shizi_dev/update"
    )

    
